package com.lmt_12;

import java.io.File;

public class FileSearch {
    public static void main(String[] args) {
        searchFile(new File("/home/rivotek/桌面/"),"an.txt");
    }

    /**
     * search File
     * @param dir
     * @param fileName
     */
    public static void searchFile(File dir,String fileName){
            if (dir == null|| !dir.exists()||dir.isFile()){
                return;
            }
        File[] files = dir.listFiles();
            if (files == null) return;
        for (File file : files) {
            //System.out.println(file.getAbsoluteFile());
            if (file.isFile()){
                if (file.getAbsolutePath().contains(fileName)){
                    System.out.println(file.getAbsoluteFile());
                    return ;
                }
            }else {
                searchFile(file,fileName);
            }
        }
    }
}
